using System;
using System.IO;
using System.Collections.Generic;
public class RedirectReaction : ReactionBase
{
    public RedirectReaction(string redirect, Dictionary<string, string> query)
        : base() {
        this.redirect = redirect;
        this.query = query;
    }
    public RedirectReaction(string redirect)
        : this(redirect, new Dictionary<string, string>()) {
    }

    readonly Dictionary<string, string> query;
    readonly string redirect;

    public override bool Redirect {
        get { return true; }
    }

    public override string RedirectLocation {
        get {
            var ret = redirect;

            if (query != null) {
                var first = true;
                foreach (var kvp in query) {
                    if (first) {
                        ret += "?";
                    }
                    else {
                        ret += "&";
                    }
                    first = false;

                    // /program.html?profile=john&index=2
                    ret += kvp.Key + "=" + kvp.Value;

                }

            }
            return ret;
        }
    }

    public override string GetContent() {
        return "";
    }

}
